package kr.saeildamil.androidstudy.ch16;

import kr.saeildamil.androiddforstudy.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class SelectDialog02 extends Activity {
	
	int mSelect = 0;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch16_selectdialog);
	}
	
	public void mOnClick(View v){
		new AlertDialog.Builder(this)
		.setTitle("Choose the Menu")
		.setIcon(R.drawable.ic_launcher)
		.setSingleChoiceItems(R.array.foods, mSelect, new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				mSelect = which;
			}
		})
		
		.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int whichButton) {	
				String[] foods = getResources().getStringArray(R.array.foods);
				TextView tv = (TextView) findViewById(R.id.ch16_selectdialog_resulttv);
				tv.setText("You choose : " + foods[mSelect]);
			}
		})
		.setNegativeButton("Close", null)
		.show();
	}
}


